package pattern.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/*
 * @author changfei
 * @date  2023/11/28 14:23
 * @description 动态代理对西那个
 */
public class DynamicProxyObject  implements InvocationHandler {
    private Station station;

    public  Station getProxyObject(Station station){
        this.station=station;
        Class<? extends Station> aClass = station.getClass();
        return (Station)Proxy.newProxyInstance(aClass.getClassLoader(), aClass.getInterfaces(),this);
    }
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("收取5%手续费");
        return method.invoke(this.station,args);
    }

    public static void main(String[] args) {
        DynamicProxyObject dynamicProxyObject=new  DynamicProxyObject();
        Station proxyObject = dynamicProxyObject.getProxyObject(new SHStation());
        proxyObject.sellTicket();
    }
}
